package com.atguigu.realtime.tests

import com.alibaba.fastjson.JSON
import com.google.gson.Gson

/**
 * Created by Smexy on 2021/7/10
 */
object JsonTest {

  def main(args: Array[String]): Unit = {


    val cat: Cat = Cat("小花")

    //将样例类创建的一个对象，转为JSON, 由于toJSONString有很多重载的方法，编译器，不确定你调用的是单个参数的方法
    //val jsonStr: String = JSON.toJSONString(cat)

    /*
      Error:(17, 32) ambiguous reference to overloaded definition,
both method toJSONString in class JSON of type (x$1: Any, x$2: com.alibaba.fastjson.serializer.SerializerFeature*)String
and  method toJSONString in class JSON of type (x$1: Any)String
match argument types (com.atguigu.realtime.tests.Cat) and expected result type String
    val jsonStr: String = JSON.toJSONString(cat)
     */
  //  println(jsonStr)

    val gson = new Gson

    val gsonJsonStr: String = gson.toJson(cat)

    println(gsonJsonStr)

  }

}

case class  Cat(var name:String)
